package com.example.miaosha.exception;

import com.example.miaosha.entity.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 * @author kangnan
 * @date 2021/5/20 0:00
 **/
// 植入代码
@ControllerAdvice
// 异步返回给前端
@ResponseBody
public class GlobalExceptionHandler {

    // 全局异常
    @ExceptionHandler(value = Exception.class)
    public R exceptionHandler(HttpServletRequest request, Exception e) {
        return R.error("服务器异常，请联系管理员！"
                + "<br/>"
                + e.getMessage()
                + "<br/>"
                + e.getStackTrace());
    }
}
